package ch07_GUI编程;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;

public class JButtonDemo {
	public static void main(String[] args) {
		BaseFrame f =new BaseFrame("JButton 演示");
		f.setLayout(new GridLayout(3,3,5,5));

		JButton[] btns =new JButton[9];
		for(int i =0;i<btns.length;i++) {
			btns[i]=new JButton();
			f.add(btns[i]);
		}
		btns[0].setText("普通按钮");

		btns[1].setText("<html><u>E</u>=MC<sup>2</sup></html>");
		btns[2].setText("带快捷键的按钮（c）");
		btns[2].setMnemonic(KeyEvent.VK_C);
		int k = btns[2].getText().indexOf(KeyEvent.VK_C);
		btns[2].setDisplayedMnemonicIndex(k);

		btns[3].setText("禁用按钮");
		btns[3].setEnabled(false);

		btns[4].setText("不带边框的按钮");
		btns[4].setBorder(null);

		btns[5].setText("不绘制内容区的按钮");
		btns[5].setContentAreaFilled(false);

		btns[6].setText("不绘制焦点的按钮");
		btns[6].setFocusable(false);

		btns[7].setText("带图片的按钮");
		btns[7].setIcon(ImageFactory.create("对号.png"));


		btns[8].setContentAreaFilled(false);

		f.showMe();
	}
}
